$(function () {
   obj.init();
});
var obj = new function () {
    'use strict';
    return {
        form:null,
        init:function () {
            this.funObj().loadData();
            this.listener();
        },
        listener:function () {
            var $this = this;

        },
        funObj:function () {
            var $this = this;
            return {
                loadData:function () {
                    $.ajax({
                        url:baseUrl+'mobile/mine/initTrustList',
                        type:'POST',
                        dataType:'json',
                        success:function (data) {
                            var str = '';
                            str += '<li class="m-list-group">当前信任设备</li>';
                            if(data.length>0){
                                $.each(data, function (id,item) {
                                    str +=
                                        '<li> 设备号:'+item['content']+',IP: '+item['extra']['ip']+
                                        '    <div class="m-right">'+
                                        '       <a href="javascript:void(0)" nodeId="'+item['id']+'" onclick="obj.funObj().askDelAction(this)" style="color: red" class="easyui-linkbutton">删除</a>'+
                                        '   </div>'+
                                        '</li>';
                                });
                            } else {
                                str += '<li>目前暂无数据</li>';
                            }
                            var dom = $(str);
                            $('#listView').empty().append(dom);
                            $.parser.parse(dom);
                        },
                        error:function (data) {
                            console.log(data);
                        }
                    });
                },
                askDelAction:function (target) {
                    var id = $(target).attr('nodeId');
                    window.top.askDelAction('提示','确认要删除该信任设备嘛？',function () {
                        $.ajax({
                            url:baseUrl+'mobile/mine/delTrust',
                            type:'POST',
                            data:{id:id},
                            dataType:'json',
                            complete:function (XMLHttpRequest) {
                                var res = XMLHttpRequest.responseJSON || XMLHttpRequest.responseText;
                                if (res.code == 200) {
                                    window.top.sendSuccessMsg(res.msg);
                                    $this.funObj().loadData();
                                } else {
                                    window.top.sendErrorMsg(res.error);
                                }
                            }
                        });
                    })
                }
            }
        }
    }
};